package com.mind.core;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public class ScheduledThreadPoolManager {
	private static Logger logger = Logger.getLogger(ScheduledThreadPoolManager.class);
	
	private ScheduledThreadPoolExecutor executor ;
	
	public ScheduledThreadPoolManager() {
		executor = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
	}

	private static ScheduledThreadPoolManager instance;
	
	public static ScheduledThreadPoolManager getInstance() {
		if(instance == null){
			synchronized (ScheduledThreadPoolManager.class) {
				if (instance == null) {
					instance = new ScheduledThreadPoolManager();
				}
			}
		}
		return instance;
	}
	
	public void schedule(Runnable command, long delay, TimeUnit unit){
		executor.schedule(command, delay, unit);
	}
	
	public void schedule(Runnable command, long delay, long period, TimeUnit unit) {
		executor.scheduleAtFixedRate(command, delay, period, unit);
	}
	
	public void remove(Runnable command){
		executor.remove(command);
	}
}
